import { defineStore } from "pinia";
import { Names } from "../../store-namespace";
import { _get, _post, _put, _delete, http } from "@/utils/axios";
import { CabinetInstruct } from "@/api/backend/index";

export const useCabinetInstruct = defineStore(Names.CabinetInstruct, {
  state: () => {
    return {
      single: <any>{},
      typeModec: <any>[], //工作模式控制的字典
      typeAutoc: <any>[], //自动工作控制的字典
      tags: <any>{},
    };
  },
  getters: {},
  actions: {
    //获取远程指令列表数据
    getList(filter: any) {
      return new Promise((resolve, reject) => {
        _get(CabinetInstruct + "/list", filter, "json", "")
          .then((res: any) => {
            console.log("获取远程指令列表数据", res);
            resolve(res);
          })
          .catch((err: any) => {
            console.log(err);
            reject(err);
          });
      });
    },
    //发送远程指令
    change(params: any) {
      return new Promise((resolve, reject) => {
        _post(CabinetInstruct + "/sendInstruction", params, "json", "")
          .then((res: any) => {
            console.log("发送远程指令", res);
            resolve(res);
          })
          .catch((err: any) => {
            console.log(err);
            reject(err);
          });
      });
    },
  },
});
